﻿using RimWorld;
using UnityEngine;
using Verse;

namespace RI_Talisman
{
    internal class RI_Projectile_ThunderCharm : Projectile
    {
        public override bool AnimalsFleeImpact => true;

        protected override void Impact(Thing hitThing, bool blockedByShield = false)
        {
            Map map = base.Map;
            base.Impact(hitThing, blockedByShield);
            GenExplosion.DoExplosion(base.Position, map, def.projectile.explosionRadius, DamageDefOf.Stun, launcher, DamageAmount, ArmorPenetration, null, equipmentDef, def, postExplosionSpawnThingDef: null, intendedTarget: intendedTarget.Thing, postExplosionSpawnChance: 0.2f, postExplosionSpawnThingCount: 1, postExplosionGasType: null, applyDamageToExplosionCellsNeighbors: false, preExplosionSpawnThingDef: null, preExplosionSpawnChance: 0f, preExplosionSpawnThingCount: 1, chanceToStartFire: 0f);
            GenExplosion.DoExplosion(base.Position, map, def.projectile.explosionRadius, DamageDefOf.EMP, launcher, DamageAmount, ArmorPenetration, null, equipmentDef, def, postExplosionSpawnThingDef: ThingDefOf.Filth_Ash, intendedTarget: intendedTarget.Thing, postExplosionSpawnChance: 0.2f, postExplosionSpawnThingCount: 1, postExplosionGasType: null, applyDamageToExplosionCellsNeighbors: false, preExplosionSpawnThingDef: null, preExplosionSpawnChance: 0f, preExplosionSpawnThingCount: 1, chanceToStartFire: 0f);
            GenExplosion.DoExplosion(base.Position, map, def.projectile.explosionRadius, DamageDefOf.Bomb, launcher, DamageAmount, ArmorPenetration, null, equipmentDef, def, postExplosionSpawnThingDef: ThingDefOf.Filth_Dirt, intendedTarget: intendedTarget.Thing, postExplosionSpawnChance: 0.2f, postExplosionSpawnThingCount: 1, postExplosionGasType: null, applyDamageToExplosionCellsNeighbors: false, preExplosionSpawnThingDef: null, preExplosionSpawnChance: 0f, preExplosionSpawnThingCount: 1, chanceToStartFire: 0f);
            CellRect cellRect = CellRect.CenteredOn(base.Position, 3);
            cellRect.ClipInsideMap(map);
            int delay = 0; 
            for (int i = 0; i < 9; i++)
            {
                delay += 45;
                IntVec3 randomCell = cellRect.RandomCell;
                map.weatherManager.eventHandler.AddEvent(new WeatherEvent_LightningStrikeDelayed(map, randomCell, delay));
            }        
        }
    }
}
